package com.whoisaa.wifitransfer.base;

import android.os.Handler;
import android.os.Message;

import java.io.IOException;
import java.net.Socket;

/**
 * @Description Thread基类
 * @Author AA
 * @DateTime 16/4/22 上午11:36
 */
public class BaseThread extends Thread {


    public static final int SERVERPOST = 3920;
    public static final String UTF_8 = "utf-8";
    public static final int buf_size = 4 * 1024;
    public static final int file_buf_size = 1024;

    /**
     * 判断连接是否断开
     * @param socket
     * @return
     */
    protected boolean isConnectionClose(Socket socket) {
        try {
            socket.sendUrgentData(0);
            return false;
        } catch (IOException e) {
            return true;
        }
    }

    /**
     * 发送Handler消息
     * @param handler
     * @param what
     * @param obj
     */
    protected void sendMessage(Handler handler, int what, Object obj) {
        Message msg = new Message();
        msg.what = what;
        msg.obj = obj;
        handler.sendMessage(msg);
//        L.error((String) obj);
    }

    protected void sendMessage(Handler handler, int what, int position, int progress) {
        Message msg = new Message();
        msg.what = what;
        msg.arg1 = position;
        msg.arg2 = progress;
        handler.sendMessage(msg);
    }

}
